#!/usr/bin/env bash

killTomcat() {
  pid=`lsof -i:8181|awk 'END{print $2}'`
  echo "pid: $pid"
  if [ "$pid" = "" ]
  then
    echo "no pid alive"
  else
    kill -9 $pid
  fi
}

cd $PROJECT_PATH/test

mvn clean install

killTomcat

rm -rf $TOMCAT_APP_PATH/webapps/ROOT
rm -f /root/disk/test-0.0.1-SNAPSHOT.jar
rm -f $TOMCAT_APP_PATH/webapps/test-0.0.1-SNAPSHOT.jar

cp $PROJECT_PATH/test/target/test-0.0.1-SNAPSHOT.jar $TOMCAT_APP_PATH/webapps/

cd $TOMCAT_APP_PATH/webapps/

salt=LUXSUN

timestamp=`date +%s`

data=$salt$timestamp

sign=`echo -n $data | openssl md5`

sign=${sign#* }

echo curl --location --request POST '122.51.160.79:9090/disk/save' \
--header 'timestamp:'$timestamp \
--header 'sign:'$sign \
--form 'file=@"test-0.0.1-SNAPSHOT.jar"'

echo `curl --location --request POST '122.51.160.79:9090/disk/save' \
--header 'timestamp:'$timestamp \
--header 'sign:'$sign \
--form 'file=@"test-0.0.1-SNAPSHOT.jar"'`

java -jar test-0.0.1-SNAPSHOT.jar &